﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" href="../Content/css/bootstrap.min.css" />
    <link rel="stylesheet" href="../Content/css/font-awesome.min.css" />
    <link rel="stylesheet" href="../Content/css/ace.min.css" />
    <link rel="stylesheet" href="../Content/css/jframe.css" />
</head>
<body ng-app="listApp" class="page-content">
    <div ng-controller="listCtrl">
        <div class="dlg-content">
            <form role="form" name="conditionForm" novalidate>
                <div class="toolbar">
                    类型 :
                    <select ng-model="categoryId">
                        <option ng-repeat="category in categories" value="{{category.id}}">{{category.name}}</option>
                    </select>

                    <button class="btn btn-sm btn-primary" ng-click="interactive.search()">
                        <i class="icon-search"></i>查询
                    </button>
                </div>
            </form>
            <p></p>
            <div class="table-responsive">
                <table id="sample-table-1" class="table table-striped table-bordered table-hover">
                    <tr>
                        <td>Code</td>
                        <td>Caption</td>
                        <td>Data Type</td>
                        <td>Description</td>
                        <td>operation</td>
                    </tr>
                    <tr ng-repeat="item in articleItemList">
                        <td>{{item.code}}</td>
                        <td>{{item.caption}}</td>
                        <td>{{item.dataType}}</td>
                        <td>{{item.description}}</td>
                        <td style="width: 130px">
                            <div class="btn-group">
                                <button class="btn btn-xs btn-primary tooltip-info" data-rel="tooltip" data-placement="bottom"
                                        title="选择" ng-click="interactive.onSelect(item)">
                                    <i class="icon-ok bigger-120"></i>
                                    选择
                                </button>
                            </div>
                        </td>
                    </tr>
                </table>
                <pagination></pagination>
            </div>
        </div>
        <div class="dlg-footer">
            <div class="center">
                <div class="btn-group">
                    <button class="btn btn-sm btn-info" ng-click="interactive.onCancel()">
                        <i class="icon-undo bigger-125"></i>
                        返 回
                    </button>
                </div>
            </div>
        </div>
    </div>
    <script src="../Config.js"></script>
    <script src="../Content/js/jquery-1.10.2/jquery-1.10.2.min.js"></script>
    <script src="../Content/js/bootstrap.min.js"></script>
    <script src="../Content/js/promise/Promise.js"></script>
    <script src="../Content/js/ace-elements.min.js"></script>
    <script src="../Content/js/ace.min.js"></script>
    <script src="../Content/js/bootbox.min.js"></script>
    <script src="../Content/js/angular-1.2.29/angular-1.2.29.min.js"></script>

    <script src="../Content/js/jquery.gritter.min.js"></script>
    <script src="../Content/js/cppei/cppei.view.js"></script>
    <script src="../Content/js/cppei/cppei.paginationPlugin.js"></script>
    <script>
        cppei.install();

        var app = angular.module('listApp', []);

        ////加载分页栏
        cppei.paginationPlugin.attach2ngApp(app);

        app.controller("listCtrl", function ($scope, $http) {
            //获取详细信息
            var paginationInst = cppei.paginationPlugin.attach2ngScope($scope, $http, jframe.getUrl('api/FieldType/List'), {
                categoryId: $scope.categoryId
            }).success(function (data) {
                cppei.busy(false);
                $scope.articleItemList = data.items;
            }).error(function (result) {
                cppei.busy(false);
                cppei.growlError(result.message);
            });

            $scope.service = {
                refresh: function () {
                    cppei.busy(true);
                    paginationInst.reload({ categoryId: $scope.categoryId });
                },
                loadCategory: function () {
                    cppei.busy(true);
                    $http({
                        method: 'get',
                        url: jframe.getUrlWithTimespan('api/FieldType/CategoryList')
                    }).success(function (result) {
                        if (result.isSuccess) {
                            debugger;
                            cppei.busy(false);
                            $scope.categories = result.data.items;
                        } else {
                            cppei.busy(false);
                            cppei.growlError(result.message);
                        }
                    }).error(function (result) {
                        cppei.busy(false);
                        cppei.growlError('error');
                    });
                }
            };

            $scope.interactive = {
                onSelect: function (fieldType) {
                    cppei.closeDialog(true, fieldType);
                },
                onCancel: function () {
                    cppei.closeDialog(false, null);
                },
                search: function () {
                    if ($scope.categoryId) {
                        $scope.service.refresh();
                    }
                }
            };

            $scope.onCreate = function () {

                window.location.href = "article_Create.html";

            }

            $scope.onEdit = function (id) {
                window.location.href = 'article_Edit.html?id=' + id;
            }

            $scope.onPublish = function (id, publishedTime) {

                publishedTime = encodeURI(encodeURI(publishedTime));

                cppei.showDialog('发布', 'Module/cms/article_publish_confirm.html?publishedTime=' + publishedTime + '&&id=' + id, $scope.onDialogClosecCallback, { width: 800, height: 280 });

            }

            // 对话框关闭事件
            $scope.onDialogClosecCallback = function (result, data) {
                if (result) {
                    paginationInst.refresh();
                    cppei.growl('发布成功！');
                } else {
                    // do nothing
                    if (data.value == '3') {
                        cppei.growl('取消发布！');
                    } else {
                        cppei.growl('发布失败！');
                    }
                }
            };

            $scope.onDelete = function (id) {

                cppei.confirm('提示', '是否删除选中文章？', function (result) {
                    if (result) {
                        $http({
                            method: 'post',
                            url: cppei.api.getUrl('Article', 'Delete'),
                            data: { Id: id }
                        }).success(function (result, status) {

                            if (result.isSuccess) {
                                paginationInst.refresh();
                            } else {
                                cppei.growlError(result.message);
                            }

                        }).error(function (result, status) {
                            //$scope.data = data || "Request failed";
                            cppei.growlError(result.message);
                        });
                    }
                });
            }
            $scope.service.loadCategory();
        });
    </script>
</body>
</html>
